package com.lanou.dao;
import com.lanou.domain.CrmStaff;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import java.util.List;

/**
 * Created by lanouhn on 17/9/27.
 */
public class StaffDaoImpl extends HibernateDaoSupport implements StaffDao{

    @Override
    public CrmStaff find(CrmStaff crmStaff) {
        //hql语句
        String hql="from CrmStaff WHERE loginName=? AND loginPwd=?";
        List<CrmStaff> allStaff = (List<CrmStaff>) getHibernateTemplate().find(hql, crmStaff.getLoginName(), crmStaff.getLoginPwd());
        //判断获取的值
        if(allStaff.size() == 1){
            return allStaff.get(0);
        }
        return null;
    }

    // 获取所有员工信息
    @Override
    public List<CrmStaff> findAll() {
        String hql="from CrmStaff";
        return (List<CrmStaff>) this.getHibernateTemplate().find(hql);
    }



    //基本数据回显，根据每条数据的id
    @Override
    public CrmStaff findById(String staffId) {
        return this.getHibernateTemplate().get(CrmStaff.class,staffId);
    }



}
